﻿using System;

namespace System.Data
{
    /// <summary>
    /// Provides relational functionality between two DataTable
    /// </summary>
    public class DataRelation
    {
        #region DataFields
        /// <summary>
        /// "ChildTableName" property data field
        /// </summary>
        string _childTableName;

        /// <summary>
        /// Holds foreign key DataColumns
        /// </summary>
        DataColumnCollection _foreignKey;

        /// <summary>
        /// "ParentTableName" property data field
        /// </summary>
        string _parentTableName;

        /// <summary>
        /// Holds primary key DataColumns
        /// </summary>
        DataColumnCollection _primaryKey;

        /// <summary>
        /// "RelationName" property data field
        /// </summary>
        string _relationName;
        #endregion

        #region Events
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public DataRelation(string relationName, DataColumnCollection primaryKey, DataColumnCollection foreignKey)
        {
            // Validate arguments
            if (string.IsNullOrEmpty(relationName))
            {
                throw new ArgumentNullException("relationName");
            }

            if (primaryKey == null || primaryKey.Count == 0)
            {
                throw new ArgumentNullException("primaryKey");
            }

            if (foreignKey == null || foreignKey.Count == 0)
            {
                throw new ArgumentNullException("foreignKey");
            }

            this._foreignKey = foreignKey;
            this._primaryKey = primaryKey;
            this._relationName = relationName;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets child table name
        /// </summary>
        public string ChildTableName
        {
            get
            {
                return this._childTableName;
            }
            set
            {
                this._childTableName = value;
            }
        }

        /// <summary>
        /// Gets foreign key
        /// </summary>
        public DataColumnCollection ForeignKey
        {
            get
            {
                return this._foreignKey;
            }
        }

        /// <summary>
        /// Gets or sets paret table name
        /// </summary>
        public string ParentTableName
        {
            get
            {
                return this._parentTableName;
            }
            set
            {
                this._parentTableName = value;
            }
        }

        /// <summary>
        /// Gets primary key
        /// </summary>
        public DataColumnCollection PrimaryKey
        {
            get
            {
                return this._primaryKey;
            }
        }

        /// <summary>
        /// Gets or sets DataRelation name
        /// </summary>
        public string RelationName
        {
            get
            {
                return this._relationName;
            }
            set
            {
                // Validate argument
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException("value");
                }

                this._relationName = value;
            }
        }
        #endregion

        #region Methods
        #endregion

        #region Event Handlers
        #endregion
    }
}
